package com.hxkj.controller;

import com.hxkj.domain.po.Site;
import com.hxkj.service.SiteService;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 站点控制层
 * <p>
 * Created by chenwei on 2018/5/15.
 */
@RestController
@RequestMapping("/site")
public class SiteController {

    @Autowired
    private SiteService siteService;

    /**
     * 获取站点列表
     *
     * @param site 站点信息
     * @return 翻页数据
     * @throws Exception
     */
    @RequiresPermissions("site:view")
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public Callable<ResultPageStruct<Site>> getList(@ModelAttribute Site site, @ModelAttribute PageTo pageParam) {
        return () -> siteService.getSiteList(site == null ? new Site() : site,pageParam);
    }

    /**
     * 获取站点切换列表
     *
     * @param
     * @return 翻页数据
     * @throws Exception
     */
    @RequestMapping(value = "/getswitcherlist", method = RequestMethod.POST)
    public Callable<List<Site>> getSwitcherList(@ModelAttribute Site site) {
        return () -> siteService.getSwitcherList(site);
    }


    /**
     * 获取站点
     *
     * @param site
     * @return 用户信息
     * @throws Exception
     */
    @RequiresPermissions("site:view")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public Callable<Site> getSite(@ModelAttribute Site site) {
        return () -> siteService.getSiteFromCache(site);
    }

    /**
     * 新增站点
     *
     * @param site 站点信息
     * @throws Exception
     */
    @RequiresPermissions("site:add")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> saveSite(@ModelAttribute Site site)  {
        return () -> siteService.saveSite(site);
    }

    /**
     * 删除站点
     *
     * @param site 站点
     * @throws Exception
     */
    @RequiresPermissions("site:remove")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> deleteSite(@ModelAttribute Site site) {
        return () -> siteService.deleteSite(site);
    }

    /**
     * 修改站点
     *
     * @param site 站点信息
     * @throws Exception
     */
    @RequiresPermissions("site:modify")
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> updateSite(@ModelAttribute Site site)  {
        return () -> siteService.updateSite(site);
    }

    /**
     * 站点排序
     *
     * @param site 站点id 数组信息
     * @throws Exception
     */
    @RequiresPermissions("site:modify")
    @RequestMapping(value = "/sort", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> siteSort(@ModelAttribute Site site) {
        return () -> siteService.SiteSort(site);
    }

}
